package com.fhj.movie.activity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.fhj.movie.baidumap.JyjMapActivity;
import com.fhj.movie.entity.JyjCinemaDetailsEntity;
import com.fhj.movie.entity.JyjCinemaEntity;
import com.fhj.movie.entity.JyjDetailListEntity;
import com.fhj.movie_fhj_01.R;
import com.fhj.utils.JsonUtils;
import com.fhj.utils.ListOrder;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class JyjCinemaDetailsDetailsActivity extends Activity {

	private TextView title,name,grade,location;
	private CheckBox like;
	
	private int position;
	
	private Map<Integer, Integer> serviceImg;
	private LinearLayout mainLayout;
	private JyjCinemaEntity entity;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_jyj_cinema_details_details);
		
		//图片数据初始化
		serviceImg = new HashMap<Integer, Integer>();
		
		
		serviceImg.put(1, R.drawable.icon_service_visa);
		serviceImg.put(2, R.drawable.icon_service_glass);
		serviceImg.put(3, R.drawable.icon_service_imax);
		serviceImg.put(4, R.drawable.icon_service_imax);
		serviceImg.put(5, R.drawable.icon_service_park);
		serviceImg.put(6, R.drawable.icon_service_love);
		serviceImg.put(7, R.drawable.icon_service_child);
		serviceImg.put(8, R.drawable.icon_service_machine);
		serviceImg.put(9, R.drawable.icon_service_wifi);
		serviceImg.put(10, R.drawable.icon_service_coffee);
		
		
		position = getIntent().getIntExtra("position", 0);

		entity = ListOrder.list.get(position);
		
		findbyId();
		
		title.setText(entity.getName());
		name.setText(entity.getName());
		grade.setText(String.valueOf(entity.getGrade())+"分");
		location.setText(entity.getAddress());
		
		mainLayout = (LinearLayout) this.findViewById(R.id.maindetails_layout);
		LinearLayout.LayoutParams mainParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		
		
		
		JyjCinemaDetailsEntity cinemaDetails = JsonUtils.getInstance().cinemaDetails;
		Log.d("", "======"+cinemaDetails.getBusline()+","+cinemaDetails.getSubwayLine()
				+","+entity.getBusline()+","+entity.getSubwayLine()
				);
		if (!cinemaDetails.getBusline().trim().equals("null")||!cinemaDetails.getSubwayLine().trim().equals("null")){
			TextView  jiaotong = new TextView(this);
			jiaotong.setLayoutParams(mainParams);
			jiaotong.setText("交通信息");
			jiaotong.setTextColor(Color.BLACK);
			mainLayout.addView(jiaotong);
			
			LinearLayout line = new LinearLayout(this);
			LinearLayout.LayoutParams jiaotongParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
			line.setLayoutParams(mainParams);
			line.setBackgroundColor(Color.WHITE);
			line.setPadding(8, 8, 8, 8);
			line.setOrientation(LinearLayout.VERTICAL);
			
			if (!cinemaDetails.getBusline().trim().equals("null")) {
				TextView  gongjiao = new TextView(this);
				gongjiao.setLayoutParams(jiaotongParams);
				gongjiao.setText("公交线路");
				gongjiao.setTextColor(Color.BLACK);
				line.addView(gongjiao);
				
				TextView  gongjiaoInfo = new TextView(this);
				gongjiaoInfo.setLayoutParams(jiaotongParams);
				gongjiaoInfo.setText(cinemaDetails.getBusline());
				gongjiaoInfo.setTextColor(Color.BLACK);
				line.addView(gongjiaoInfo);
			}
			if (!cinemaDetails.getSubwayLine().trim().equals("null")) {
				TextView  ditie = new TextView(this);
				ditie.setLayoutParams(jiaotongParams);
				ditie.setText("地铁线路");
				ditie.setTextColor(Color.BLACK);
				line.addView(ditie);
				
				TextView  ditieInfo = new TextView(this);
				ditieInfo.setText(cinemaDetails.getSubwayLine());
				ditieInfo.setLayoutParams(jiaotongParams);
				ditieInfo.setTextColor(Color.BLACK);
				line.addView(ditieInfo);
			}
			
			mainLayout.addView(line);
		}
		
		//提供的服务的显示
		List<JyjDetailListEntity> detailLists = cinemaDetails.getDetailLists();
		
		TextView tesexinxi = (TextView)this.findViewById(R.id.maindetails_tesexinxi);
		if (detailLists!=null&&detailLists.size()>0) {
			tesexinxi.setVisibility(View.VISIBLE);
			LinearLayout tese = (LinearLayout)this.findViewById(R.id.maindetails_tesexinxi_layout);
			
			for(int i = 0 ;i<detailLists.size();i++){
				JyjDetailListEntity en = detailLists.get(i);
				LinearLayout  item = new LinearLayout(this);
				item.setOrientation(LinearLayout.HORIZONTAL);
				item.setBackgroundColor(Color.WHITE);
				item.setPadding(8, 8, 8, 8);
				item.setGravity(Gravity.CENTER_VERTICAL);
				
				LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
				
				ImageView image = new ImageView(this)	;
				image.setImageResource(serviceImg.get(en.getType()));
				image.setLayoutParams(params);
				item.addView(image);
				
				TextView  textcontent = new TextView(this);
				textcontent.setTextColor(Color.BLACK);
				textcontent.setLayoutParams(params);
				textcontent.setText(en.getDesc());
				item.addView(textcontent);
				
				tese.addView(item);
			}
		}
		if (!entity.getNewCoupon().startsWith("null")&&!entity.getNewCoupon().isEmpty()) {
			TextView  youhui = new TextView(this);
			youhui.setLayoutParams(mainParams);
			youhui.setText("优惠信息");
			youhui.setTextColor(Color.BLACK);
			mainLayout.addView(youhui);
			
			TextView  info = new TextView(this);
			youhui.setLayoutParams(mainParams);
			info.setTextColor(Color.BLACK);
			String youhuiInfo= entity.getNewCoupon();
			youhuiInfo = youhuiInfo.replace("<br/>", "\n");
			youhuiInfo = youhuiInfo.replace("<br />", "\n");
			info.setText(youhuiInfo);
			info.setBackgroundColor(Color.WHITE);
			info.setPadding(8, 8, 8, 8);
			mainLayout.addView(info);
		}
		
		
	}

	private void findbyId() {
		// TODO 自动生成的方法存根
		title =  (TextView)this.findViewById(R.id.movie_details_title);
		name =  (TextView)this.findViewById(R.id.movie_details_name);
		grade =  (TextView)this.findViewById(R.id.movie_details_grade);
		location =  (TextView)this.findViewById(R.id.movie_details_location);
		like = (CheckBox)this.findViewById(R.id.movie_details_like);
		ImageView  jiantou = (ImageView)this.findViewById(R.id.movie_details_youjiantou);
		jiantou.setVisibility(View.INVISIBLE);
	}
	
	public void btnJiuCuo(View  view){
		Intent  intent = new Intent(this, JyjErrorCommitActivity.class);
		startActivity(intent);
	}
	public void btnMap(View view ){
		Intent  intent  = new Intent(this, JyjMapActivity.class);
		startActivity(intent);
	}
	public void btnDianhua(View  view){
//		Intent  intent = new Intent(Intent.ACTION_CALL);//自动直接播出号码
		Intent   intent =  new Intent(Intent.ACTION_DIAL);//调用拨号界面，手动播出电话
		intent.setData(Uri.parse("tel://"+entity.getTel()));
		startActivity(intent);
	}
}
